
from DrissionPage import ChromiumPage, ChromiumOptions
import random
import time
co = ChromiumOptions().set_local_port(9765)
co.set_browser_path(
    r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe')
page = ChromiumPage(addr_or_opts=co)

# page.get('https://www.baidu.com')


tab = page.latest_tab
# 访问网页
tab.get('https://qiye.qizhidao.com/batch-query-result?matchId=029cfd71-37b1-45a6-893d-234845e8d53d')

# tab.timeout()

time.sleep(random.uniform(3, 5))

# url_value = []
for i in range(149):
    url_value = []
    data_html = tab.html

    url_list = tab.eles(
        'xpath://div[@class="el-table__fixed-body-wrapper"]/table/tbody/tr//a[@class="link"]/@href')

    for url in url_list:
        url_value.append(str(url.attr('href')))
    try:
        next_page = tab.ele(
            'xpath://div[@class="el-pagination"]/button[@class="btn-next"]/i')
        next_page.click()
        time.sleep(random.uniform(3, 5))
    except:
        print('翻页失败')
        break

    with open('./url_value.txt', 'a+', encoding='utf-8') as f:
        for i in url_value:
            f.write(i+'\n')
